﻿using System;

namespace TopVisionVideoStream
{
    class Model_VideoConferencFeatures
    {

        #region 闪光灯

        /// <summary>
        /// 闪灯消息
        /// </summary>
        const string flashCommand = "闪光灯,闪光灯";

        /// <summary>
        /// 闪光灯控制
        /// </summary>
        public static void Flash()
        {
            SendMessage(flashCommand);
        }

        #endregion


        #region 对焦控制

        /// <summary>
        /// 对焦消息
        /// </summary>
        const string focusCommand = "点对焦,{0},{1},{2},{3}";

        /// <summary>
        /// 对焦控制
        /// </summary>
        /// <param name="width">画面宽度</param>
        /// <param name="height">画面高度</param>
        /// <param name="x">鼠标X坐标</param>
        /// <param name="y">鼠标Y坐标</param>
        public static void Focus(int width, int height, int x, int y)
        {
            string cmd = string.Format(focusCommand, width, height, x, y);
            SendMessage(cmd);
        }

        #endregion


        #region 变焦控制

        /// <summary>
        /// 变焦消息
        /// </summary>
        const string zoomCommand = "焦距,{0}";

        /// <summary>
        /// 变焦控制
        /// </summary>
        /// <param name="z">放大倍数[0-6]</param>
        public static void Zoom(double z)
        {
            z = Math.Abs(z);
            z = z > 6 ? 6 : z;
            string cmd = string.Format(zoomCommand, z * 10);
            SendMessage(cmd);
        }

        #endregion


        #region 标记控制

        /// <summary>
        /// 标记消息
        /// </summary>
        const string markCommand = "标记,{0},{1},{2},{3},{4},{5},{6},{7},{8}";
        /// <summary>
        /// 清除标记
        /// </summary>
        const string clearMarkCommand = "清除照片标示,清除照片标示";

        /// <summary>
        /// 标记控制
        /// </summary>
        /// <param name="width">画面宽度</param>
        /// <param name="height">画面高度</param>
        /// <param name="sX">标记起点X</param>
        /// <param name="sY">标记起点Y</param>
        /// <param name="eX">标记终点X</param>
        /// <param name="eY">标记终点Y</param>
        /// <param name="pT">标记类型
        /// 1 = 画直线    3 = 画空心矩形    5 = 空心圆    10 = 箭头
        /// </param>
        /// <param name="color">标记颜色
        /// #ff7200    #9943e3    #24def4    #07df8b    #288fe7    #ffe404     #ef3030     #000000
        /// 橙色       紫色       青色       绿色       蓝色       黄色        红色        黑色
        /// </param>
        /// <param name="pWidth">标记线宽
        /// 1,2,4,6
        /// </param>
        public static void Mark(int width, int height, int sX, int sY, int eX, int eY, int pT, string color, int pWidth)
        {
            string cmd = string.Format(markCommand, width, height, sX, sY, eX, eY, pT, color, pWidth);
            SendMessage(cmd);
        }

        /// <summary>
        /// 清除标记
        /// </summary>
        public static void ClearMark()
        {
            SendMessage(clearMarkCommand);
        }

        #endregion


        #region 拍照控制

        /// <summary>
        /// 拍照消息
        /// </summary>
        const string takePhotoCommand = "拍照,拍照";
        /// <summary>
        /// 退出拍照消息
        /// </summary>
        const string leaveTakingPhotoCommand = "结束MatrixImageView,结束MatrixImageView";

        /// <summary>
        /// 拍照控制
        /// </summary>
        public static void TakePhoto()
        {
            SendMessage(takePhotoCommand);
        }

        /// <summary>
        /// 退出拍照
        /// </summary>
        public static void LeaveTakingPhoto()
        {
            SendMessage(leaveTakingPhotoCommand);
        }

        #endregion


        #region 文字控制

        /// <summary>
        /// 文字消息
        /// </summary>
        const string txtCommand = "文字,{0}";
        /// <summary>
        /// 清除文字
        /// </summary>
        const string clearTxtCommand = "文字消失,文字消失";

        /// <summary>
        /// 发送文字
        /// </summary>
        /// <param name="txt"></param>
        public static void SendText(string txt)
        {
            string cmd = string.Format(txtCommand, txt);
            SendMessage(cmd);
        }

        public static void SendText(string id, string txt)
        {
            string cmd = string.Format(txtCommand, txt);
            SendMessage(id, cmd);
        }

        /// <summary>
        /// 清除文字
        /// </summary>
        public static void ClearText()
        {
            SendMessage(clearTxtCommand);
        }

        #endregion


        #region 转语音

        /// <summary>
        /// 转语音消息
        /// </summary>
        const string voiceOnlyCommand = "冻结,冻结";


        private static bool isVoice = false;
        private static int preCameraIndex = 0;
        /// <summary>
        /// 转语音控制
        /// </summary>
        public static void VoiceOnly()
        {
            isVoice = !isVoice;
            SendMessage(voiceOnlyCommand);
            Configuration.Core.bSetVideoType(isVoice ? 0 : 1);
        }

        #endregion


        #region 画面控制

        /// <summary>
        /// 亮度消息
        /// </summary>
        const string brightnessCommand = "相机参数调节,brightness,{0}";
        /// <summary>
        /// 对比度消息
        /// </summary>
        const string contrastCommand = "相机参数调节,contrast,{0}";

        /// <summary>
        /// 亮度调节
        /// </summary>
        /// <param name="value">亮度偏差值[正数增加，负数减少]</param>
        public static void BrightnessModify(int value)
        {
            string cmd = string.Format(brightnessCommand, value);
            SendMessage(cmd);
        }

        /// <summary>
        /// 对比度调节
        /// </summary>
        /// <param name="value">对比度偏差值[正数增加，负数减少]</param>
        public static void ContrastModify(int value)
        {
            string cmd = string.Format(contrastCommand, value);
            SendMessage(cmd);
        }

        #endregion


        #region 设置分辨率

        //static string RslCmd = "设置分辨率,{0},{1},{2}";

        //public static void SetResolution(Resolution _rsl, BitRate _brate, FrameRate _frate)
        //{
        //    string strRsl = "switch_cif";
        //    string strBRate = "400";
        //    string strFRate = "15";


        //    switch (_rsl)
        //    {
        //        case Resolution.r240P:
        //            strRsl = "switch_cif";
        //            break;
        //        case Resolution.r480P:
        //            strRsl = "switch_vga";
        //            break;
        //        case Resolution.r720P:
        //            strRsl = "switch_720p";
        //            break;
        //        case Resolution.r1080P:
        //            strRsl = "switch_1080p";
        //            break;
        //        default:
        //            break;
        //    }

        //    switch (_brate)
        //    {
        //        case BitRate.b200:
        //            strBRate = "200";
        //            break;
        //        case BitRate.b400:
        //            strBRate = "400";
        //            break;
        //        case BitRate.b800:
        //            strBRate = "800";
        //            break;
        //        case BitRate.b1600:
        //            strBRate = "1600";
        //            break;
        //        default:
        //            break;
        //    }

        //    switch (_frate)
        //    {
        //        case FrameRate.f10:
        //            strFRate = "10";
        //            break;
        //        case FrameRate.f15:
        //            strFRate = "15";
        //            break;
        //        default:
        //            break;
        //    }

        //    SendMessage(string.Format(RslCmd, strRsl, strBRate, strFRate));
        //}

        static string RslCmd = "设置分辨率,{0}";

        public static void SetResolution(string _rsl)
        {
            string strRsl = _rsl;
            string strBRate = "400";
            string strFRate = "15";


            //switch (_rsl)
            //{
            //    case Resolution.r240P:
            //        strRsl = "switch_cif";
            //        break;
            //    case Resolution.r480P:
            //        strRsl = "switch_vga";
            //        break;
            //    case Resolution.r720P:
            //        strRsl = "switch_720p";
            //        break;
            //    case Resolution.r1080P:
            //        strRsl = "switch_1080p";
            //        break;
            //    default:
            //        break;
            //}

            SendMessage(string.Format(RslCmd, strRsl));
            //var ret = Configuration.Core.bRequestIFrame();
            //Console.WriteLine("bRequestIFrame ");
        }

        static string BitCmd = "设置码率,{0}";

        /// <summary>
        /// 设置码率
        /// </summary>
        /// <param name="bit">码率</param>
        public static void SetBitrate(string bit)
        {
            SendMessage(string.Format(BitCmd, bit));
        }

        #endregion


        #region Helper

        public static void SendMessage(string message)
        {
            Helper.SendMessage(Configuration.CallingID, message);
        }

        public static void SendMessage(string id, string message)
        {
            Helper.SendMessage(id, message);
        }

        #endregion

    }

    ///// <summary>
    ///// 分辨率
    ///// </summary>
    //[Flags]
    //public enum Resolution
    //{
    //    NONE = 0,
    //    // 自动
    //    AUTO = 1,
    //    // 240p
    //    r240P = 2,
    //    // 480p
    //    r480P = 4,
    //    // 720p
    //    r720P = 8,
    //    // 1080p
    //    r1080P = 16,
    //}

    /// <summary>
    /// 码率
    /// </summary>
    public enum BitRate
    {
        // 100 kbps
        b100,
        // 200 kbps
        b200,
        // 400 kbps
        b400,
        // 800 kbps
        b800,
        // 1600 kbps
        b1600,
        // 3200 kbps
        b3200,
    }

    /// <summary>
    /// 祯率
    /// </summary>
    public enum FrameRate
    {
        // 5 fps
        f5,
        // 10 fps
        f10,
        // 15 fps
        f15,
        // 20 fps
        f20,
        // 30 fps
        f30,
    }
}
